using System;
using System.Collections.Generic;
using System.Net.Http;
using System.Threading.Tasks;
using TCEntity;

namespace TCClientService
{
  public static class ImageService
  {
    /// <summary>
    /// 上传图像。
    /// </summary>
    /// <param name="client">HTTP客户端。</param>
    /// <param name="user">给定用户。</param>
    /// <param name="picture">图像数据。</param>
    /// <param name="success">成功时执行的方法。</param>
    /// <param name="failure">失败时执行的方法，传入失败原因字符串。</param>
    /// <param name="InternetFailure">网络错误时执行的方法。</param>
    /// <returns></returns>
    public static async Task UploadAsync(this HttpClient client, User user, byte[] picture, Action success, Action<string> failure, Action InternetFailure)
    {
      var request = new HttpRequestMessage(HttpMethod.Post, "./Image/upload");
      await TCHttpService.SendAsync<object>(client, request, (user, picture), _ => success(), failure, InternetFailure);
    }
    /// <summary>
    /// 下载用户的所有图像。
    /// </summary>
    /// <param name="client">HTTP客户端。</param>
    /// <param name="user">给定用户。</param>
    /// <param name="success">成功时执行的方法，传入结果图像列表。</param>
    /// <param name="failure">失败时执行的方法，传入失败原因字符串。</param>
    /// <param name="InternetFailure">网络错误时执行的方法。</param>
    /// <returns></returns>
    public static async Task DownloadAsync(this HttpClient client, User user, Action<List<Image>> success, Action<string> failure, Action InternetFailure)
    {
      var request = new HttpRequestMessage(HttpMethod.Get, "./Image/download/user");
      await TCHttpService.SendAsync(client, request, user, success, failure, InternetFailure);
    }
    /// <summary>
    /// 下载用户指定日期的图像。
    /// </summary>
    /// <param name="client">HTTP客户端。</param>
    /// <param name="user">给定用户。</param>
    /// <param name="date">指定日期。</param>
    /// <param name="success">成功时执行的方法，传入结果图像列表。</param>
    /// <param name="failure">失败时执行的方法，传入失败原因字符串。</param>
    /// <param name="InternetFailure">网络错误时执行的方法。</param>
    /// <returns></returns>
    public static async Task DownloadAsync(this HttpClient client, User user, DateTime date, Action<List<Image>> success, Action<string> failure, Action InternetFailure)
    {
      var request = new HttpRequestMessage(HttpMethod.Get, "./Image/download/date");
      await TCHttpService.SendAsync(client, request, (user,date), success, failure, InternetFailure);
    }
    /// <summary>
    /// 下载指定图像。
    /// </summary>
    /// <param name="client">HTTP客户端。</param>
    /// <param name="user">给定用户。</param>
    /// <param name="imageId">图像Id。</param>
    /// <param name="success">成功时执行的方法，传入结果图像。</param>
    /// <param name="failure">失败时执行的方法，传入失败原因字符串。</param>
    /// <param name="InternetFailure">网络错误时执行的方法。</param>
    /// <returns></returns>
    public static async Task DownloadAsync(this HttpClient client, User user, int imageId, Action<Image> success, Action<string> failure, Action InternetFailure)
    {
      var request = new HttpRequestMessage(HttpMethod.Get, "./Image/download/id");
      await TCHttpService.SendAsync(client, request, (user,imageId), success, failure, InternetFailure);
    }
    /// <summary>
    /// 删除云端图像。
    /// </summary>
    /// <param name="client">HTTP客户端。</param>
    /// <param name="user">给定用户。</param>
    /// <param name="imageId">图像Id。</param>
    /// <param name="success">成功时执行的方法。</param>
    /// <param name="failure">失败时执行的方法，传入失败原因字符串。</param>
    /// <param name="InternetFailure">网络错误时执行的方法。</param>
    /// <returns></returns>
    public static async Task DeleteAsync(this HttpClient client, User user, int imageId, Action success, Action<string> failure, Action InternetFailure)
    {
      var request = new HttpRequestMessage(HttpMethod.Delete, "./Image/delete");
      await TCHttpService.SendAsync<object>(client, request, (user,imageId), _ => success(), failure, InternetFailure);
    }

    public static async Task FilterAsync(this HttpClient client, int[] order, Action<List<Image>> success, Action<string> failure, Action InternetFailure)
    {
      var request = new HttpRequestMessage(HttpMethod.Get, "./Image/filter");
      await TCHttpService.SendAsync(client, request, order, success, failure, InternetFailure);
    }
  }
}
